<template>
    <view class="bg-content">
        <div style="background-color: white;">
            <u-cell-item :arrow="false" use-label-slot :title-style="{'width': '100%'}" v-for="(item, index) in tbStoreClassGroupList" :key="item.id">
                <div slot="icon">
                </div>
                <div slot="title" style="padding-left: 10px;">
                    {{item.name}}
                    <div style="float: right; color: grey; font-size: 12px;">
                        显示顺序：{{item.displayOrder}}
                    </div>
                    <div style="text-align: right;">
                        <u-button plain size="mini" type="default" style="margin-left: 5px;" @click="deleteItem(item, index)">删除</u-button>
                        <u-button plain size="mini" type="default" style="margin-left: 5px;"
                                  @click="navigateTo('/pages/sub/sub2-store-platform/store-platform/store-platform-system-class/store-platform-system-class-edit/index', null, item)">
                            编辑
                        </u-button>
                        <u-button plain size="mini" type="default" style="margin-left: 5px;"
                                  @click="navigateTo('/pages/sub/sub2-store-platform/store-platform/store-platform-system-class/store-platform-system-class-grade2/index', null, item)">
                            详情
                        </u-button>
                    </div>
                </div>
                <div slot="label">
                </div>
                <div slot="right-icon">
                </div>
                <!--默认value属性-->
                <div>
                </div>
            </u-cell-item>
        </div>

        <div style="padding-top: 50px;" v-if="!tbStoreClassGroupList.length">
            <u-empty text="数据为空" mode="data"></u-empty>
        </div>

        <div style="padding-bottom: 60px;"></div>

        <div class="custom-bottom-button">
            <label @click="navigateTo('/pages/sub/sub2-store-platform/store-platform/store-platform-system-class/store-platform-system-class-add/index', {parentId: 'root', parentIds: 'root,#', grade: 1})">
                添加一级分类
            </label>
        </div>
    </view>
</template>

<script>

    import {TbStoreClassService} from "@/dev/services/tb-store-class.service";
    import {CommonUtil} from "@/dev/core/utils/common.util";

    export default {
        data() {
            return {
                tbStoreClassGroupList: []
            }
        },
        onShow() {
            const _self = this;
            new TbStoreClassService().findTbStoreClassList({
                communityId: this.globalVariable.userInfo.tbStore.communityId,
                grade: 1,
                deleted: 0,
                orderBy: 'display_order asc'
            }).then(result => {
                console.log(result);
                _self.tbStoreClassGroupList = result;
            });
        },
        methods: {
            deleteItem(item, index) {
                const _self = this;
                CommonUtil.alert({
                    title: '提示！',
                    content: '确定删除吗？',
                    showCancel: true, // 是否显示取消按钮
                    success: function (res) {
                        if (res.cancel) { // 点击取消,默认隐藏弹框
                        } else { // 点击确定
                            new TbStoreClassService().deleteTbStoreClass(item).then(result => {
                                CommonUtil.alert("删除成功");
                                _self.tbStoreClassGroupList.splice(index, 1);
                            })
                        }
                    }
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
</style>
